﻿@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.BLL
@{
    ViewBag.Title = "Index";
    var provinceList = ServiceFactory.D_ProvinceServiceInstance.GetDProvinceAll();
    var selectList = new SelectList(provinceList, "ProvinceID", "ProvinceName");
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul class="nav nav-tabs">
    <li class="active"><a href="/ServiceProvider/ServiceProviderBranchIndex">服务商网点列表</a></li>
    <li class="Add-R"><a href="/ServiceProvider/ServiceProviderBranchEdit/0">添加服务商网点</a></li>
</ul>
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <label>服务商名称：</label>
        <input id="serviceProviderName" name="serviceProviderName" class="input-medium" placeholder="请输入服务商名称" type="text" value="" maxlength="50" />
        <label>网点名称：</label>
        <input id="branchName" name="branchName" class="input-medium" placeholder="请输入网点名称" type="text" value="" maxlength="50" />
        <br />
        <label>网点地址：</label>
        @Html.DropDownList("provinceId", ConvertToSelector.Instance.D_ProvinceConvertToSelectList())
        省
        <select id="cityId">
            <option value="0">请选择</option>
        </select>
        市

        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
    </div>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="serviceProviderBranchList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="80">服务商名称</th>
                <th width="100">网点名称</th>
                <th width="60">网点编码</th>
                <th width="50">所在省</th>
                <th width="50">所在市</th>
                <th width="50">联系人</th>
                <th width="50">联系电话</th>
                <th width="40">是否启用</th>
                <th width="40">操作</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#serviceProviderBranchList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/ServiceProvider/ServiceProviderBranchList",
                    aoColumns: [
                        {
                            "mData": null, "bSortable": false, "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "ServiceProviderName", "bSortable": false },
                        {
                            "mData": "BranchName", "bSortable": false, "fnRender": function (nRow) {
                                return "<a class='Edit-R' href='/ServiceProvider/ServiceProviderBranchEdit/" + nRow.aData.ID + "' title='edit'>" + nRow.aData.BranchName + "</a>";
                            }
                        },
                        { "mData": "BranchCode", "bSortable": false },
                        { "mData": "ProvinceName", "bSortable": false },
                        { "mData": "CityName", "bSortable": false },
                        { "mData": "ContactName", "bSortable": false },
                        { "mData": "ContactPhone", "bSortable": false },
                         { "mData": "IsAvailable" },
                        { "mData": "ID", "bSortable": false }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(8)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var html = "<a class='Edit-R' href='/ServiceProvider/ServiceProviderBranchEdit/" + aData.ID + "' title='edit'><i class='icon-edit'></i></a>";
                        html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/ServiceProvider/ServiceProviderBranchUpdateStatus','serviceProviderBranchList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(9)', nRow).html(html);

                    }
                });
            imgPreview();
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }
        function search() {
            /*给查询对象赋值*/
            queryParamList.ServiceProviderTypeId = $("#serviceProviderTypeId").val();
            queryParamList.ServiceProviderName = $("#serviceProviderName").val();
            queryParamList.ServiceType = $("#ServiceType").val();
            queryParamList.BranchName = $("#branchName").val();
            queryParamList.ProvinceId = $("#provinceId").val();
            queryParamList.CityId = $("#cityId").val();
            $("#serviceProviderBranchList").dataTable().fnDraw();
            imgPreview();
        }

        $(function () {
            provinceChange();
            $("#provinceId").change(function () {
                provinceChange();
            });
        });
        function provinceChange() {
            var provinceID = $("#provinceId").val();
            $.ajax({
                url: "/Common/GetCityList?provinceID=" + provinceID,
                success: function (data) {
                    var html = "<option value='0'>请选择</option>";
                    if (data && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value='";
                            html += data[i].Value;
                            html += "'>" + data[i].Text;
                            html += "</option>";
                        }
                    }
                    $("#cityId").html(html);
                }
            });
        }
    </script>
}


